{% extends 'item-bank-exercise-manage/exercise-set/layout.html.twig' %}

{% block title %}{{'item_bank_exercise.testpaper_practice'|trans}} - {{ exercise.title }} - {{ parent() }}{% endblock %}
{% do script(['app/js/item-bank-exercise/assessment/index.js']) %}
{% set course_side_nav = 'assessment' %}
{% block main_heading_class %}course-main-header{% endblock %}

{% block main %}
  <div class="cd-main">
    <div class="cd-main__body">
      <div class="task-list-header clearfix">
        <label class="switch-title">{{ 'item_bank_exercise.testpaper_practice.open'|trans }}</label>
        <label class="cd-switch {% if exercise.assessmentEnable == 1 %}checked{% endif %}" style="vertical-align: -4px;">
          <input id="switch" type="radio" value="{{ exercise.assessmentEnable }}" data-url="{{ path('item_bank_exercise_manage_assessment_exercise_open', {exerciseId: exercise.id}) }}" checked>
        </label>
        <input type="hidden" value="{{ path('item_bank_exercise_manage_can_module_open',{exerciseId:exercise.id, type:'assessment'}) }}" id="canOpen">
        <span class="text-14 ml20" style="color: #adadad; line-height: 1;">
          {{ 'item_bank_exercise.testpaper_practice.tip'|trans }}
        </span>
      </div>
      {% if exercise.assessmentEnable == 1 %}
        <div class="js-all-container">
          <div class="exercise-container">
            <ul class="exercise-nav exercise-nav-tabs mb0 col-sm-9">
              {% for module in modules %}
                <li class="text-center {% if moduleId == module.id %}active{% endif %}">
                  {% if moduleId == module.id %}
                    {{ module.title }}
                    <a href="#modal" data-toggle="modal" class="js-edit-module cd-link-minor" data-url="{{ path('item_bank_exercise_manage_assessment_module_edit', {exerciseId: exercise.id, moduleId: module.id}) }}"><i class="cd-icon cd-icon-edit edit-icon"></i></a>
                  {% else %}
                    <a href="{{ path('item_bank_exercise_manage_assessment', {exerciseId: exercise.id, moduleId: module.id}) }}">{{ module.title }}</a>
                  {% endif %}
                </li>
              {% endfor %}
              <li class="text-center {% if count(modules) >= 5 %}hidden{% endif %}">
                <a href="#modal" data-toggle="modal" data-url="{{ path('item_bank_exercise_manage_assessment_module_create', {exerciseId: exercise.id}) }}"><i class="cd-icon cd-icon-add"></i>{{ 'item_bank_exercise.assessment_exercise.add_new_module'|trans }}</a>
              </li>
            </ul>
            <div class="col-sm-3 pull-right">
              <a href="#modal" data-toggle="modal" id="add-testpaper" data-url="{{ path('item_bank_exercise_manage_assessment_add_list', {exerciseId: exercise.id, moduleId: moduleId, isPage: 0}) }}" class="cd-btn cd-btn-ghost-primary">{{ 'item_bank_exercise.assessment_exercise.add_assessment'|trans }}</a>
              <button class="cd-btn cd-btn-ghost-primary mlm js-batch-delete" data-url="{{ path('item_bank_exercise_manage_batch_delete_assessment', {exerciseId: exercise.id}) }}" style="color: rgba(255,72,32,1); border-color: rgba(255,72,32,1);">{{ 'item_bank_exercise.assessment_exercise.remove_assessment'|trans }}</button>
            </div>
          </div>
          <div class="js-assessment-container">
            <table class="table cd-table">
              <thead>
                <tr>
                  <th width="10%"><input type="checkbox" autocomplete="off" data-role="batch-select"></th>
                  <th width="50%" class="text-center">{{ 'course.testpaper_manage.create.name'|trans }}</th>
                  <th width="20%" class="text-center">{{ 'question.nums'|trans }}/{{ 'item_bank_exercise.assessment.total_score'|trans }}</th>
                  <th width="20%" class="text-center">{{ 'operation'|trans }}</th>
                </tr>
              </thead>
              <tbody>
                {% for assessment in assessments if assessments %}
                  <tr>
                    <td><input class="js-checkbox" value="{{ assessmentExercises[assessment.id].id }}" data-id="{{ assessment.id }}" type="checkbox" autocomplete="off" data-role="batch-item"></td>
                    <td class="text-center">{{ assessment.name }}</td>
                    <td class="text-center">{{'course.testpaper_manage.count'|trans({'%itemCount%': assessment.item_count})}}/{{'course.testpaper_manage.score'|trans({'%score%': assessment.total_score})}}</td>
                    <td class="text-center">
                      <a href="{{ path('question_bank_manage_testpaper_preview', {id: questionBank.id, assessmentId: assessment.id}) }}" class="cd-btn cd-btn-link-primary" target="_blank">{{ 'course.btn.preview'|trans }}</a>
                      <button class="cd-btn cd-btn-link-primary js-delete-single" data-url="{{ path('item_bank_exercise_manage_delete_assessment', {exerciseId: exercise.id, id: assessmentExercises[assessment.id].id }) }}" style="color: rgba(255,72,32,1);">{{ 'form.btn.remove'|trans }}</button>
                    </td>
                  </tr>
                {% else %}
                  <tr>
                    <td colspan="20">
                      <div class="cd-empty">{{ 'my.teaching.question_bank.testpaper.empty'|trans }}</div>
                    </td>
                  </tr>
                {% endfor %}
              </tbody>
            </table>
            {{ web_macro.paginator(paginator) }}
          </div>
        </div>
      {% else %}
        <div class="empty task-empty js-task-empty">
          <i class="es-icon es-icon-book task-empty-icon"></i>
          {{ 'item_bank_exercise.assessment_exercise.empty'|trans }}
        </div>
      {% endif %}
    </div>
  </div>
{% endblock %}